package uk.co.agileworks.bidpirate.service;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import org.junit.Before;
import org.junit.Ignore;
//import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;

import uk.co.agileworks.bidpirate.model.Bid;
import uk.co.agileworks.bidpirate.model.Item;
import uk.co.agileworks.bidpirate.test.DataSet;

//@Ignore
@ContextConfiguration(locations = "file:src/main/webapp/WEB-INF/spring-servlet.xml")
public class EbaySessionIT extends AbstractTransactionalJUnit4SpringContextTests {

	private final DataSet dataSet = new DataSet();

	@Autowired
	private EbayFacade ebayFacade;
	private EbaySession ebaySession;

	@Ignore
	@Test
	public void placeBid() {
		Item item = new Item(270544665239L);
		Bid bid = new Bid();
		bid.setMaxBid(0.99);
		bid.setItem(item);
		bid.setUser(dataSet.getUser1());
		signIn();
		ebaySession.placeBid(bid);
		LOGGER.trace(ebaySession.confirmBid());
		signOut();
	}

	@Before
	public void setUp() {
		ebaySession = ebayFacade.createEbaySession();
	}

	@Test
	public void signInAndOut() {
		signIn();
		assertTrue(ebaySession.signedIn(dataSet.getUser1()));
		signOut();
		assertFalse(ebaySession.signedIn(dataSet.getUser1()));
	}

	private void signIn() {
		ebaySession.signIn(dataSet.getUser1());
	}

	private void signOut() {
		ebaySession.signOut();
	}

	protected static final Logger LOGGER = LoggerFactory.getLogger(EbaySessionIT.class);
}
